package cn.yomigaeri.signal.producer;

import cn.yomigaeri.common.entity.dto.SignalDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SignalProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    // 单向发送消息
    public void sendSaveMessage(SignalDTO signalDTO) {
        rocketMQTemplate.convertAndSend("signalToSave" + signalDTO.getCarId() % 2, signalDTO);
        log.info("发送信号存入数据库的消息成功:{}", signalDTO);
    }

    public void sendCheckMessage(SignalDTO signalDTO) {
        rocketMQTemplate.convertAndSend("signalToCheck", signalDTO);
        log.info("发送信号检查的消息成功:{}", signalDTO);
    }
}
